#coding:utf-8

"""
    通过xpath和bs4提取的字符串数据,都是Unicode编码
"""


import sys 
reload(sys)
sys.setdefaultencoding('utf-8')
import requests

from bs4 import BeautifulSoup
from lxml import etree


#腾讯招聘--社招  地址分析
#url = "https://hr.tencent.com/position.php?lid=2218&tid=87&keywords=python"
#
#https://hr.tencent.com/position.php?keywords=c&start=30#a
#
#详情页
#https://hr.tencent.com/position_detail.php?id=45653&keywords=c&tid=0&lid=0
#
#tid--------岗位----0代表全部
#lib--------地区----0代表全部
#keywords---搜索关键词
#start起始值
url = "https://hr.tencent.com/position.php?keywords=python&start=0"

headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"}

response = requests.get(url, headers=headers)

html = response.content

html_obj = etree.HTML(html)

td = html_obj.xpath('//table[@class="tablelist"]//tr[@class="h"]/td[@class="l"]')
print(td[0].text)
print(111111111111111111111111111)
tr = html_obj.xpath('//tr[@class="even"]')
print(tr)
print(tr[0])
print(tr[0].tag)
print(tr[0][1])
print(tr[0][1].tag)
print(tr[0][1].text)


#--------------------------------分 隔 符-------------------------
print("*"*50)

soup = BeautifulSoup(html, 'lxml')
print(len(soup.find_all('tr')))
tr_e = soup.find_all("tr", {"class":"even"})
print(len(tr_e))
tr_o = soup.find_all("tr", {"class":"odd"})
print(len(tr_o))
#找出所有属性中class为even或odd的tr标签
print(len(soup.find_all("tr", {"class":["even", "odd"]})))
#找出所有指定属性的tr和xxx标签
print(len(soup.find_all(["tr", "xxx"], {"class":["even", "odd"]})))
#根据属性查找所有指定的标签
print(len(soup.find_all(attrs={"class": ["even", "odd"]})))
#根据class属性查找所有指定的标签
print(len(soup.find_all(class_=["even", "odd"])))

#找出所有class为even和odd的标签
print(len(soup.select(".even")))
print(len(soup.select(".even, .odd")))
print(len(soup.select("[class='even'], [class='odd']")))
